﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InSafetyAirClient.GUI.Plane
{
    public partial class DeleteP : UserControl
    {

        private static List<InSafetyAirService.Plane> planes = null;
        private AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();

        public DeleteP()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (InSafetyAirService.Plane plane in planes)
            {
                if (plane.registrationNo.Equals(comboBox1.Text))
                {
                    ServiceSingle.Instance.getService().DeleteFromDatabase(plane);
                    populateList();
                }
            }
        }

        private void DeleteP_Load(object sender, EventArgs e)
        {
            if (!this.DesignMode)
            {
                populateList();
            }
        }

        private void populateList()
        {
            comboBox1.Items.Clear();
            ServiceSingle servS = ServiceSingle.Instance;
            planes = servS.getService().GetAll(typeof(InSafetyAirService.Plane).Name).OfType<InSafetyAirService.Plane>().ToList();
            foreach (InSafetyAirService.Plane plane in planes)
            {
                autoComplete.Add(plane.registrationNo);
                comboBox1.Items.Add(plane.registrationNo);
            }
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            comboBox1.AutoCompleteCustomSource = autoComplete;
        }
    }
}
